package com.skyc.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.skyc.entity.Clothes;
import com.skyc.entity.User;
import com.skyc.service.collectionService;
import com.skyc.service.liuLanService;
import com.skyc.service.impl.collectionServiceImpl;
import com.skyc.service.impl.liulanServiceImpl;

/**
 * Servlet implementation class toindexServlet
 */
@WebServlet("/douser_collectionServlet")
public class douser_collectionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		HttpSession session = request.getSession();
		int ccid=Integer.valueOf(request.getParameter("ccid"));
//		int ccid=1;
		System.out.println("ccid="+ccid);
		User user = (User) session.getAttribute("user"); 
		collectionService cd=new collectionServiceImpl();
		cd.deletecollection(user, ccid);//删除
		List<Clothes> uc=cd.ucollection(user);//重新查询个人收藏
		for (Clothes c : uc) {
			c.setCimgurl(c.getCimgurl().substring(0, c.getCimgurl().indexOf('/')));
		}
		session.setAttribute("uc", uc);
		request.getRequestDispatcher("user_collection_show.jsp").forward(request, response);

	}
}
